package com.cnswhy.cloud.server.core.dao;

import com.cnswhy.cloud.common.core.base.mapper.SuperMapper;
import com.cnswhy.cloud.server.core.entity.IotChargingLineTransOrder;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * Mapper 接口
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2021-03-08
 */
@Repository
public interface IotChargingLineTransOrderMapper extends SuperMapper<IotChargingLineTransOrder> {
    @Select("select count(1) from t_iot_charging_line_trans_order t where t.terminal_id = #{terminalId} and t.status = 2 ")
    Long getSuccessCount(@Param("terminalId") String terminalId);
    @Select("select ifnull(sum(t.trans_amt),0) from t_iot_charging_line_trans_order t where t.terminal_id = #{terminalId} and t.status = 2 ")
    Long getSuccessTransAmt(@Param("terminalId") String terminalId);
    @Select("select ifnull(sum(t.split_amt),0) from t_split_trans_record t where t.order_id in (select s.order_id from t_iot_charging_line_trans_order s " +
            "where s.terminal_id = #{terminalId} and s.status = 2) and split_customer_id = #{customerId}")
    Long getTotalSplitAmt(@Param("terminalId") String terminalId, @Param("customerId") Long customerId);
    @Select("select ifnull(sum(t.split_amt),0) from t_split_trans_record t where t.order_id in (select s.order_id from t_iot_charging_line_trans_order s " +
            "where s.merchant_id = #{merchantId} and s.status = 2) and split_customer_id = #{customerId}")
    Long getTotalSplitAmtAndMerchantId(@Param("merchantId") Long merchantId, @Param("customerId") Long customerId);
}
